<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>个人评论列表</title>
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/iconfont.css">
  <link rel="stylesheet" href="css/main.css">
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <script src="./libs/template-web.js"></script>
  <!-- 引入地址就是 -->
  <script src="./js/http.js"></script>
  <!-- 引入分页插件所需的文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <script src="./libs/jquery.twbsPagination.js"></script>
</head>

<body>
  <div class="container-fluid">
    <div class="common_title">
      评论列表
    </div>
    <div class="container-fluid common_con">
      <table class="table table-striped table-bordered table-hover mp20">
        <thead>
          <tr>
            <th>作者</th>
            <th>评论</th>
            <th>评论在</th>
            <th>提交于</th>
            <th>状态</th>
            <th class="text-center" width="100">操作</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>小周</td>
            <td>这是一条测试评论，欢迎光临</td>
            <td>《世界，你好》</td>
            <td>2017-07-04 12:00:00</td>
            <td>已批准</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-warning btn-xs">拒绝</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr class="danger">
            <td>小右</td>
            <td>你好啊，交个朋友好吗？</td>
            <td>《世界，你好》</td>
            <td>2017-07-06 14:10:00</td>
            <td>待审核</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-info btn-xs">批准</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr class="danger">
            <td>老周</td>
            <td>不好</td>
            <td>《世界，你好》</td>
            <td>2017-07-09 22:22:00</td>
            <td>待审核</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-info btn-xs">批准</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr class="danger">
            <td>中周</td>
            <td>How are you?</td>
            <td>《世界，你好》</td>
            <td>2017-07-09 18:22:00</td>
            <td>待审核</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-info btn-xs">批准</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>小右</td>
            <td>I am fine thank you and you?</td>
            <td>《世界，你好》</td>
            <td>2017-07-11 22:22:00</td>
            <td>已批准</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-warning btn-xs">拒绝</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>哈哈</td>
            <td>一针见血</td>
            <td>《世界，你好》</td>
            <td>2017-07-22 09:10:00</td>
            <td>已批准</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-warning btn-xs">拒绝</a>
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>武秀英</td>
            <td>外影广条同取水权科速工与。矿身面却属次养导务作者用品油调。高石期品极放存斗一号口消别共去。</td>
            <td>《世界，你好》</td>
            <td>1970-03-15 11:31:50</td>
            <td>已拒绝</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>胡娟</td>
            <td>采参什正面准观提干在易东统。走部系取团商机酸科往证和流物实则。入程用指学行利划影现清关织方。</td>
            <td>《第四篇示例文章》</td>
            <td>1970-03-23 14:16:57</td>
            <td>已拒绝</td>
            <td class="text-center">
              <a href="javascript:void(0);;" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>邵艳</td>
            <td>国新研目心思力品家织通还如周气长多。话它思造约众系压程它过去全。必导则达发前何西最老四关向。</td>
            <td>《第一篇示例文章》</td>
            <td>1970-04-19 12:34:27</td>
            <td>已拒绝</td>
            <td class="text-center">
              <a href="javascript:editTr( 'trashed',10 );" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          <tr>
            <td>唐军</td>
            <td>好联律物联使进很们有严这里月之。实养件矿商除政究定划必火起划六。内百那则变次引持只情车各地织持。</td>
            <td>《第四篇示例文章》</td>
            <td>1970-04-24 11:22:29</td>
            <td>已批准</td>
            <td class="text-center">
              <a href="javascript:editTr( 'rejected',11 );" class="btn btn-warning btn-xs">拒绝</a>
              <a href="javascript:editTr( 'trashed',11 );" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
        </tbody>
      </table>
      <div class="row text-center">
        <!-- 引入分页结构 -->
        <ul id="pagination" class="pagination-sm">
        </ul>
        <!-- 当前页没有数据的情况下显示 -->
        <p>没有数据!</p>
      </div>

    </div>
  </div>
  <script id="commentList" type="text/html">
    {{each data.data v}}
    <tr>
      <td>{{v.author}}</td>
      <td>{{v.content}}</td>
      <td>{{v.title}}</td>
      <td>{{v.date}} {{v.time}}</td>
      <td>{{v.state}}</td>
      {{if v.state=='待审核'}}
      <td class="text-center">
        <a href="javascript:void(0);;" data_id="{{v.id}}" class="btn btn-info btn-xs btn-confirm">批准</a>
        <a href="javascript:void(0);;" data_id="{{v.id}}" class="btn btn-warning btn-xs btn-refuse">拒绝</a>
      </td>
      {{else}}
      <td class="text-center">
        <a href="javascript:void(0);;" data_id="{{v.id}}" class="btn btn-danger btn-xs btn-delete">删除</a>
      </td>
      {{/if}}
    </tr>
    {{/each}}
  </script>
  <script>
    $(function () {
      //封装函数
      let myPage = 1;

      function getData(myPage, callback) {
        $.ajax({
          url: BigNew.comment_search,
          data: {
            page: myPage,
            perpage: 6
          },
          success: function (backData) {
            // console.log(backData);
            if (backData.code == 200) {
              let res = template('commentList', backData);
              $('tbody').html(res);
            }
            if (callback != null && backData.data.data.length != 0) {
              callback(backData);
              $('#pagination').show().siblings('p').hide();
            } else if (backData.data.data.length == 0 && myPage == 1) {
              $('#pagination').hide().siblings('p').show();
            } else if (backData.data.data.length == 0 && myPage - 1 == totalPage) {
              myPage -= 1;
              $('#pagination').twbsPagination('changeTotalPages', backData.data.totalPage, mypage)
            }
          }
        })
      }
      getData(myPage, function (backData) {
        $('#pagination').twbsPagination({
          totalPages: backData.data.totalPage,
          visiblePages: 5,
          first: '首页',
          prev: '上一页',
          next: '下一页',
          last: '尾页',
          onPageClick: function (event, page) {
            //2.2 第二次,发送获取文章列表的ajax请求:
            //根据点击获得的页码 发送请求获得文章列表
            //将点击时的页码数赋值给全局的mypage 方便删除时显示当前电点击页
            mypage = page;
            getData(page, null);
          }
        })

      });
      $('tbody').on('click', '.btn-delete', function () {
        let commentId = $(this).attr('data_id');
        $.ajax({
          type: 'post',
          url: BigNew.comment_delete,
          data: {
            id: commentId
          },
          success: function (backData) {
            console.log(backData);
            if (backData.code == 200) {
              if (confirm('确认删除吗')) {
                alert('删除成功');
                getData(mypage, null)
              }
            }
          }
        })
      });
      $('tbody').on('click', '.btn-refuse', function () {
        let commentId = $(this).attr('data_id');
        $.ajax({
          type: 'post',
          url: BigNew.comment_reject,
          data: {
            id: commentId
          },
          success: function (backData) {
            // console.log(backData);
            getData(myPage, null);
          }
        })
      })
      $('tbody').on('click', '.btn-confirm', function () {
        let commentId = $(this).attr('data_id');
        $.ajax({
          type: 'post',
          url: BigNew.comment_pass,
          data: {
            id: commentId
          },
          success: function (backData) {
            // console.log(backData);
            getData(myPage, null);
          }
        })
      })














    })
  </script>
</body>

</html>